#include <stdio.h>
#include <stdlib.h>

struct student
{
	char sno[8];
	char name[20];
	char sex;
	int age;
	double score;
	struct student *next;
};

void insert_node(struct student *head, struct student *p);
void traverse(struct student *head);
void delete_node(struct student *head);

int main(void)
{
	struct student *h, *q;
	int i, n;

	printf("Input the number of students: ");
	scanf("%d", &n);
	getchar();
	h = (struct student *)malloc(sizeof(struct student));
	h->next = NULL;
	printf("Input %d students' information(sex, sno, name, age, score):\n", n);
	for (i = 0; i < n; i++)
	{
		q = (struct student *)malloc(sizeof(struct student));
		scanf("%c%s%s%d%lf", &q->sex, q->sno, q->name, &q->age, &q->score);
		getchar();
		insert_node(h, q);
	}

	traverse(h);

	while (h->next)
		delete_node(h);
	free(h);
	h = NULL;

	return 0;
}

void insert_node(struct student *head, struct student *p)
{
	p->next = head->next;
	head->next = p;
}

void traverse(struct student *head)
{
	struct student *p;

	puts("  sno              name       sex  age   score");
	p = head->next;
	while (p)
	{
		printf("%s%20s%5c%5d%8.1f\n", p->sno, p->name, p->sex, p->age, p->score);
		p = p->next;
	}
}

void delete_node(struct student *head)
{
	struct student *p;

	p = head->next;
	head->next = p->next;
	printf("Deleting the student %s ...\n", p->sno);
	free(p);
	p = NULL;
}